(defun our-fourth (x)
  (car (cdddr x)))


(defun greater (x y)
  (if (> x y)
    x
    y))


;; 5.a. Enigma: 	Return true if one of the element is nil in a list
;; 5.b. Mystry		Returns where you can find x in y. Else returns nill.
;; 			1, (2 3 4 1 2 1 4 1)
;;

;;; 7. find out if an element in a list is a list

(defun is-list (lst)
  (if (null lst)
    nil
    (if (listp (car lst))
      lst
      (is-list (cdr lst)))))


;;; 8. Give iterative and recursive definitions of a function that
;;;  (a) takes a positive integer and prints that many dots.
;;;   (b) takes a list and returns the number of times the symbol a occurs
;;;        ink.
;;;        
(defun do-dots-itr (num)
  (do ( (i num (- i 1)) )
    ( (eq i 0) 'end)
    (format t ".")))

(defun do-dots-rec (num)
  (if (eq 0 num)
    'done
    (progn
      (format t ".")
      (do-dots-rec (- num 1)))))

(defun count-symbol-itr (x lst)
  (let ((cnt 0) (len (length lst)))
    (do ( (i 1 (+ 1 i)) )
      ( (> i len) 'done)
      (if (eq x (Car lst))
	(setf cnt (+ 1 cnt))
	cnt)
      (setf lst (cdr lst)))
    cnt))

(defun count-symbol-rec (x lst)
  (if (null lst)
    0
    (if (eq (car lst) x)
      (+ 1 (count-symbol-rec x (cdr lst) ))
      (+ 0 (count-symbol-rec x (cdr lst) )))))


;;; 9. A friend is trying to write a function that returns the sum of all the
;;; non-nil elements in a list. He has written two versions of this function,
;;; and neither of them work. Explain what's wrong with each, and give a
;;; correct version:
;;;(a) (defun summit ( 1 s t )
;;;     (remove nil 1st)
;;;     (apply #' + 1st))
;;;(b) (defun summit (1st)
;;;       (let ((x (car 1st)))
;;;       (if (null x)
;;;       (summit (cdr 1st))
;;;       (+ x (summit (cdr 1st))))))
;;;

(defun summit (lst)
  (remove nil lst)
  (apply #'+ (remove nil lst)))

	
(defun summit-rec (1st)
  ;(if (null 1st)
   ; 0
    (let ((x (car 1st)))
     (if (null x)
      (summit (cdr 1st))
       (+ x (summit (cdr 1st))))));)

